#include<iostream>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<sys/select.h>

void SetNonBlock(int sockfd)
{
    int fl=fcntl(sockfd,F_GETFL);
    if(fl<0)
    {
        perror("fcntl");
        return;
    }
    fcntl(sockfd,F_SETFL,fl|O_NONBLOCK);
}

int main()
{
    SetNonBlock(0);
    char buffer[1024];
    while(true)
    {
        ssize_t n=read(0,buffer,sizeof(buffer)-1);
        if(n>0)
        {
            buffer[n]=0;
            printf("#%s",buffer);
        }
        else if(n==0)
        {
            printf("read end of file!\n");
            break;
        }
        else
        {
            if(errno == EAGAIN ||errno== EWOULDBLOCK);
            {
                printf("你的数据没有准备好，下次再来吧!\n");
                sleep(1);
                continue;
            }
            if(errno == EINTR)
            {
                sleep(1);
                continue;
            }
            else
            {
                perror("read error");
            }
            sleep(1);
        }
    }
}